Oil Spills in California by county

portfolios

Here is a cool little project on mapping oil spills in California

Leonardo Feitosa true
02-22-2021

Hello guys!

It’s been a while since I’ve last posted here, right?

This time I’ll show you some new mapping skills I learned recently thanks to Allison Horst and Casey O’Hara!

I got data on the records of California oil spills by county in 2008 from this website https://gis.data.ca.gov/datasets/7464e3d6f4924b50ad06e5a553d71086_0/data and created a few data visualizations to show exactly where oil spills occurred in an interactive map. I also created a choropleth map based on the counts of oil spills per county so we can see where they most occurred in 2008.

Here are the plots!

hide
## Read in the data
### Oil spills by county
ca_oil_spills <- read_sf(here("data", "oil_spills", "Oil_Spill_Incident_Tracking_%5Bds394%5D.shp")) %>% 
  clean_names() %>% 
  rename(object_id = objectid,
         dfg_control = dfgcontrol,
         oes_number = oesnumber,
         date = dateofinci,
         inland_marine = inlandmari,
         time = timeofinci,
         location = specificlo,
         city = localecity,
         county_name = localecoun) 

  
### California counties shape file
ca_counties <- read_sf(here("data", "ca_counties", "CA_Counties_TIGER2016.shp")) %>% 
  clean_names() %>% 
  dplyr::select(name) %>% 
  rename(county_name = name)
hide
## Oil spill data wrangling
ca_oil_spills_tidy <- ca_oil_spills %>%
  mutate(date = as.Date(date)) %>% 
  mutate(date = ymd(date)) %>% 
  mutate(year = year(date)) %>% 
  dplyr::select(date, year, longitude, latitude, city, county_name, inland_marine)

Interactive map of California oil spills in 2008

hide
tmap_mode("view")

tm_shape(ca_counties) +
  tm_fill("county_name") +
  tm_shape(ca_oil_spills_tidy) +
  tm_dots()

Part 2

hide
## Counts of California oil spills by county
ca_oil_spills_join <- ca_counties %>% 
  st_join(ca_oil_spills_tidy)

oil_spills_count <- ca_oil_spills_join %>% 
  filter(inland_marine %in% c("Inland")) %>% 
  count(county_name.x, inland_marine) %>%
  mutate(n = as.numeric(n))


ggplot(data = oil_spills_count) +
  geom_sf(aes(fill = n),
          color = "black",
          size = 0.5) +
  scale_fill_viridis_c() +
  labs(title = "Inland oil spill records by county in California for 2008",
       fill = "Number of oil spill records") +
  theme_bw() +
  theme(axis.text = element_text(size = 10, face = "bold", color = "black"),
        panel.grid = element_blank())